package com.bjsxt.userscenter.head.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.userscenter.common.controller.BaseController;
import com.bjsxt.userscenter.common.util.ConstatFinalUtil;
import com.bjsxt.userscenter.users.pojo.AUsers;
import com.bjsxt.userscenter.users.service.IUsersService;
/**
 * 用户登陆后的Controller
 * @author hou
 *
 */
@Controller
@RequestMapping("/head/users")
public class UsersHeadController extends BaseController
{
	@Resource
	private  IUsersService usersService;
	/**
	 * 登陆后的首页
	 */
	@RequestMapping("/main")
	public String main()
	{
		ConstatFinalUtil.LOGGER.info("----main----");
		return "/head/users/main";
		
	}
	/**
	 * 用户修改页面
	 */
	@RequestMapping("/usersUpdate")
	public String usersUpdate(HttpServletRequest request)
	{
		ConstatFinalUtil.LOGGER.info("----usersUpdate----");
		HttpSession session = request.getSession();
		AUsers users = (AUsers) session.getAttribute("users");
		//根据ID查询用户
		Map<String, Object>condMap = new HashMap<String, Object>();
		condMap.put("id", users.getId());
		users = this.usersService.findOneUsersService(condMap);
		request.setAttribute("users", users);
		return "/head/users/usersUpdate";
		
	}
	/**
	 * 用户修改提交页面
	 */
	public String usersUpdateSubmit(HttpServletRequest request)
	{
		ConstatFinalUtil.LOGGER.info("---usersUpdateSubmit----");
		HttpSession session = request.getSession();
		//AUsers users = request
		return info;
		
	}
	/**
	 * 退出
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request,HttpSession session)
	{
		ConstatFinalUtil.LOGGER.info("---- logout ----");
		/* 将session中的信息删除 */
		session.removeAttribute("users");
		session.removeAttribute("lastLoginTime");
		
		/* 操作Token */
		String token = request.getParameter("token");
		if(token == null)
		{
			token = "" ; 
		}
		if(!"".equalsIgnoreCase(token))
		{
			ConstatFinalUtil.TOKENS_MAP.remove(token);
		}
		
		this.info = ConstatFinalUtil.INFO_JSON.getString("8") ;
		/*request.setAttribute("info", info);
		return "/back/login" ; 
		*/
		session.setAttribute("info", info);
		return "redirect:/login.htm" ; 
	}
}
